#!/bin/bash
ASSIGNMENT_NUM=lab3
SIMTRAXROOT=../
SAMPLE_DIR=${SIMTRAXROOT}samples/
SCENE_DIR=${SAMPLE_DIR}scenes

ASSEMBLY=${SAMPLE_DIR}src/atomtrace/rt-llvm.s
# hardware configuration file
CONFIGS=${SAMPLE_DIR}configs/bigcache.config

NUM_PROCS=32
NUM_ICACHE_BANKS=16
NUM_ICACHES=2
THREADS_PER_PROC=1

L1_ON=1
DCACHE_AREA_ON=0

L1_CONFIG=""
DCACHE_CONFIG="--ignore-dcache-area"
# simulation report file
OUTPUT_FILE=../${ASSIGNMENT_NUM}_l1_${L1_ON}_dcachearea_${DCACHE_CONFIG}_report.txt

RENDER_CORNELL=
RENDER_CONFERENCE=

updateConfig() {
    echo "config updating"
    if [ "$L1_ON" = 0 ]
    then
        L1_CONFIG="--l1-off"
    else
        L1_CONFIG=""
    fi
    #echo "config l1 on or off finished"

    if [ "$DCACHE_AREA_ON" = 1 ]
    then
        DCACHE_CONFIG=""
    else
        DCACHE_CONFIG="--ignore-dcache-area"
    fi
    #echo "config dcache ignore finished"

    OUTPUT_FILE=../${ASSIGNMENT_NUM}_l1_${L1_ON}_dcachearea_${DCACHE_AREA_ON}_report.txt
    #echo "output file name config finish"

    CORNELL_OBJ=$SCENE_DIR/cornell/CornellBox.obj
    CORNELL_VIEW=$SCENE_DIR/cornell/cornell.view
    CORNELL_LIGHT=$SCENE_DIR/cornell/cornell.light

    CONFER_OBJ=$SCENE_DIR/conference/conference.obj
    CONFER_VIEW=$SCENE_DIR/conference/conference.view
    CONFER_LIGHT=$SCENE_DIR/conference/conference.light

    CORNELL_SCENE="--model $CORNELL_OBJ --view-file $CORNELL_VIEW --light-file $CORNELL_LIGHT"

    CONFERENCE_SCENE="--model $CONFER_OBJ --view-file $CONFER_VIEW --light-file $CONFER_LIGHT"

    SIMTRAXCONF="--disable-usimm --load-assembly $ASSEMBLY --num-thread-procs $NUM_PROCS --num-icache-banks $NUM_ICACHE_BANKS --num-icaches $NUM_ICACHES $DCACHE_CONFIG $L1_CONFIG --l2-off --config-file $CONFIGS"


    RENDER_CORNELL="./simtrax $CORNELL_SCENE $SIMTRAXCONF"

    RENDER_CONFERENCE="./simtrax $CONFERENCE_SCENE $SIMTRAXCONF"

}

#$RENDER_CORNELL
SingleRun () {
    updateConfig
    echo "Render configuration:"
    echo $RENDER_CONFERENCE
    echo "Output file:"
    echo $OUTPUT_FILE
    ${RENDER_CONFERENCE} > $OUTPUT_FILE
    echo "Done."
}

SingleTMConfRun () {
    L1_ON=1
    DCACHE_AREA_ON=0
    echo "Turn on l1 and ignore dcahe area"
    #SingleRun
    
    L1_ON=0
    echo "Turn off l1 now"
    #SingleRun

    L1_ON=1
    DCACHE_AREA_ON=1
    echo "L1 turn on again without ignore dcache area"
    SingleRun
}

SingleTMConfRun
#gthumb ./out.png &
